package com.wct.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author WEI
 * @date 2018/6/30 14:51
 */
public class MyBatisUtil {

    private static SqlSessionFactory sqlSessionFactory = null;
    static {
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream("MyBatis-Config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private MyBatisUtil(){}

    public static SqlSession getSqlSessiong(){
        return sqlSessionFactory.openSession();
    }
}
